package Year22_Month06.day08;

public class 相同的树_递归 {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        return isSame(p,q);
    }

    public boolean isSame(TreeNode left,TreeNode right){
        //如果左右子树为空就肯定相同
        if(left == null && right == null) return true;
        //如果左右子树不为空并且值相等就继续去检测对应的左右子树
        if(left != null && right != null && left.val == right.val){
            return isSame(left.left,right.left) && isSame(left.right,right.right);
        }
        return false;
    }
}
